<?php
session_start();
$openid=NULL;
if (isset($_GET['op'])){
    $openid=$_GET['op'];
    $_SESSION['openid']=$openid;
}
if (isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
}
if (empty($openid)){
    echo '请关闭当前页面，重写进入';
    exit;
}

include_once("./c/config.php");
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqliTwo->error);}
$sql="select isok from users where openid='".$openid."'  limit 0, 1";
$query=$mysqli->query($sql);
$isok=0;
$name=$hao=$phone='';
if($query->num_rows>0){
   $getUser=$query->fetch_assoc();
   $isok=$getUser['isok'];
   if (0 == $isok || 2 == $isok ){
       $getUser='';
       $sql="select name,hao,phone from users where openid='".$openid."'  limit 0, 1";
       $query=$mysqli->query($sql);
       $getUser=$query->fetch_assoc();
       $name=$getUser['name'];
       $hao=$getUser['hao'];
       $phone=$getUser['phone'];
   }
   
}
$sql="select p2,p3,p4 from zhang where openid='".$openid."'  limit 0, 1";
$query=$mysqli->query($sql);
$p2Yes=$p3Yes=$p4Yes='';
if($query->num_rows>0){
    $zhang=$query->fetch_assoc();
    $p2Yes=$zhang['p2'];
    $p3Yes=$zhang['p3'];
    $p4Yes=$zhang['p4'];
}

$sql="SELECT msg FROM `vote` where openid='".$openid."'  limit 0, 1 ";
$query=$mysqli->query($sql);
$voteMsg='';
if($query->num_rows>0){
    $voteMsg='has';
}


$sql="SELECT COUNT(uid) as count,uid FROM `piao` GROUP BY uid ";
$query=$mysqli->query($sql);
$piaoArr=array();
$piaoArr[1]=0;$piaoArr[2]=0;$piaoArr[3]=0;$piaoArr[4]=0;$piaoArr[5]=0;$piaoArr[6]=0;$piaoArr[7]=0;$piaoArr[8]=0;$piaoArr[9]=0;$piaoArr[10]=0;
$piaoArr[11]=0;
$piaoArr[12]=0;
$piaoArr[13]=0;
$piaoArr[14]=0;
$piaoArr[15]=0;
$piaoArr[16]=0;
$piaoArr[17]=0;
$piaoArr[18]=0;
$piaoArr[19]=0;
$piaoArr[20]=0;
$piaoArr[21]=0;
while ($list=$query->fetch_assoc()){
    $piaoArr[$list['uid']]=$list['count'];
}


$sql="SELECT * FROM `p5new` where openid='".$openid."'  limit 0, 1 ";
$query=$mysqli->query($sql);
$w1=$w2=$w3=$w4=$w5='';
if($query->num_rows>0){
    $getWu=$query->fetch_assoc();
    $w1=$getWu['w1'];
    $w2=$getWu['w2'];
    $w3=$getWu['w3'];
    $w4=$getWu['w4'];
    $w5=$getWu['w5'];
    
}

?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>凤凰城小区首次业主大会</title>
<style>
html,body{font-size:16px;width:100%;font-size:12px;color:#fff;font-family:Microsoft YaHei, Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;}
body, div{position:relative;padding:0px;margin:0px auto;max-width:750px;}
.weui-dialog{position:fixed;z-index:5000;width:80%;max-width:300px;top:50%;left:50%;-webkit-transform:translate(-50%,-50%);transform:translate(-50%,-50%);background-color:#FFF;text-align:center;border-radius:3px;overflow:hidden}.weui-dialog__hd{padding:1.3em 1.6em .5em}.weui-dialog__title{font-weight:400;font-size:36px}.weui-dialog__bd{padding:0 1.6em .86em;min-height:55px;font-size:15px;line-height:1.3;word-wrap:break-word;word-break:break-all;color:#999}.weui-dialog__bd:first-child{padding:1.2em 20px .1em;color:#353535}.weui-dialog__ft{position:relative;line-height:48px;font-size:18px;display:-webkit-box;display:-webkit-flex;display:flex}.weui-dialog__ft:after{content:" ";position:absolute;left:0;top:0;right:0;height:1px;border-top:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(.5);transform:scaleY(.5)}.weui-dialog__btn{display:block;-webkit-box-flex:1;-webkit-flex:1;flex:1;color:#3CC51F;text-decoration:none;-webkit-tap-highlight-color:transparent;position:relative}.weui-dialog__btn:active{background-color:#EEE}.weui-dialog__btn:after{content:" ";position:absolute;left:0;top:0;width:1px;bottom:0;border-left:1px solid #D5D5D6;color:#D5D5D6;-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleX(.5);transform:scaleX(.5)}.weui-dialog__btn:first-child:after{display:none}.weui-dialog__btn_default{color:#353535}.weui-dialog__btn_primary{color:#0BB20C}@media screen and (min-width:1024px){.weui-dialog{width:35%}}.weui-mask{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0;background:rgba(0,0,0,.6)}
.weui-mask_transparent{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0}
.js_dialog{display:none;}
-webkit-touch-callout:none;
-webkit-user-select:none;
html{-ms-touch-action:none;}
*{-webkit-overflow-scrolling:touch;}
.container{background:#fff;height:100%;min-height:600px;}
.p1, .p5, .p4, .p3, .p2{display:none;}
 
.p2 span{padding-left:12px;}
.p2 .title{padding-left:0;}

::-webkit-scrollbar-track
{
	-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
	border-radius: 10px;
	background-color: #F5F5F5;
}

::-webkit-scrollbar
{
	width: 12px;
	background-color: #F5F5F5;
}

::-webkit-scrollbar-thumb
{
	border-radius: 10px;
	-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
	background-color: #555;
}
.selTitle{
font-size:13px;
padding:0 4px 10px 4px;
}
.ui-checkbox{width:40%;}
.ui-checkbox-end{width:40%;}
.jqradiowrapper{
    display: block;
    float: left;
}
.p1-img{position:absolute;width:100%;color:#000;opacity:.9;}
.p1 #toptitle{background-color:transparent;color:#000;}
.p2 #toptitle{padding-top:6px;}
.p1 .red{font-weight:700;color:#000;padding:10px;z-index:2;}
.p1  .formfield{border-bottom:none;}
.sub-title{margin-bottom:15px; width:100%;padding-right:3%;font-size:14px;text-align:right;}
.sub-title h3{font-size:18px;}
.p1-bg{position:absolute;border-radius:10px;width:100%;height:100%;top:0;left:0;background:#fff;opacity:.3;}

.p5 .uhao{color:red;padding-right:10px;}
</style>
<link rel="stylesheet" href="./css/jqmobo.css?v=3">
</head>
<body>
<div class="container p1">
  <img class="p1-img" src="./img/b.jpg?v=3">
  
  <div id="toptitle" style="margin-top: 0px;">
        <h1 class="htitle" id="htitle">凤凰城小区首次业主大会</h1>
  </div>
  <div class="sub-title">
     <h3 class="htitle" >维护业主权益，共建美好家园。</h3>
  </div>
 
   <div id="divQuestion">
        
        <div class="field ui-field-contain" id="div1" req="1" topic="1" gm="" data-role="fieldcontain" type="1">
             <div class="field-label">
                              姓名：<span class="req">*</span>
             </div>
             <div class="ui-input-text" style="position:relative;">
             	<input type="text" id="name" value="<?php echo $name; ?>" name="q1"  placeholder="输入您的姓名" >
             </div>
             <div class="errorMessage error-name"></div>
        </div>
        <div class="field ui-field-contain">
            <div class="field-label">房号：<span class="req">*</span></div>
            <div class="ui-input-text" style="position:relative;"><input type="text" id="hao" value="<?php echo $hao; ?>" name="q2" placeholder="输入您的房号" ></div>
            <div class="errorMessage error-hao"></div>
        </div>
        
        <div class="field ui-field-contain">
            <div class="field-label">手机号码：<span class="req">*</span></div>
            <div class="ui-input-text" style="position:relative;"><input type="number" id="phone" value="<?php echo $phone; ?>" name="q2" placeholder="输入您的手机号码" ></div>
            <div class="errorMessage error-phone"></div>
        </div>
        
        <div id="divSubmit" style="padding: 0px 20px 10px;">
            <div class="voteDiv">
                 <div>
                     <div id="ctlNext" class="goNext button blue">提交</div>
                 </div>
            </div>
         </div>
        
        <div id="divDesc" class="formfield">
                <div class="p1-bg"></div> 
                <span class="description red">
                     用户信息注册：<br>
&nbsp; &nbsp; &nbsp; 用户注册，并通过审核后，方可参与投票</span>
            </div>
            <br /><br /><br />
   </div>  
</div>


<?php include 'p2.php'; ?>
<?php include 'p3.php'; ?>
<?php include 'p4.php'; ?>
<?php include 'p5.php'; ?>


<div class="js_dialog">
<div class="weui-mask"></div>
<div class="weui-dialog">
        <div class="weui-dialog__bd weui-msg"></div>
        <div class="weui-dialog__ft">
            <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary weui-btn">知道了</a>
        </div>
</div>
</div>

<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
<?php if (1 == $isok){ ?>
$(".p1").hide();
$(".p2").show();
<?php }else{ ?>
$(".p2").hide();
$(".p1").show();
<?php } ?>
 
$(function(){
  $(".goNext").click(function(){
      var _name=$("#name").val();
      var _hao=$("#hao").val();
      var _phone=$("#phone").val();
      $(".errorMessage").html("");
      
      if('' == _name){
    	 $(".error-name").html("请输入您的姓名");
        return;
      }
      if('' == _hao){
    	  $(".error-hao").html("请输入您的房号");
          return;
        }
      if('' == _phone){
    	  $(".error-phone").html("请输入您的手机号");
          return;
        }


      $.post("./api/?c=user", {name:_name,hao:_hao,phone:_phone}, function(data){
          console.log(data.s);
          if(1 == data.s){
             $(".p1").hide();
             $(".p2").fadeIn();
             return;
          }
          if(2 == data.s){
        	  _popMsg('您的资料未通过管理员审核');return;
          }
    	  _popMsg('您已提交成功，等待审核');return;

      }, "json");
     
   });
  function _popMsg(msg){$(".weui-msg").html(msg);$(".js_dialog").show();}
  
   
   

   $("#name").blur(function(){
	   if('' != $("#name").val()){
            $(".error-name").html("");
	   } 
	 });
   $("#hao").blur(function(){
	   if('' != $("#hao").val()){
            $(".error-hao").html("");
	   }
   });
   $("#phone").blur(function(){
	   if('' != $("#phone").val()){
            $(".error-phone").html("");
	   }
   });
   $(".js_dialog").click(function(){
       $(".js_dialog").hide();
	 });
   var _p2Yes='';
   $(".p2-yes").click(function(){
	   _p2Yes='yes';
	   $(".p2-no .jqradio").removeClass("jqchecked");
       $(".p2-yes .jqradio").addClass("jqchecked");
	});
   $(".p2-no").click(function(){
	   _p2Yes='no';
	   $(".p2-yes .jqradio").removeClass("jqchecked");
       $(".p2-no .jqradio").addClass("jqchecked");
	});
   $(".p2-next").click(function(){
	   if('' == _p2Yes){
		   _popMsg('您是否同意《凤凰城小区业主委员会章程》');return;
	   }
	   $.post("./api/?c=pz", {pyes:_p2Yes,p:'p2'}, function(data){
	    	 $(".p2").hide();
	    	 $(".p3").fadeIn();    
	   }, "json");
	});
   var _p3Yes='';
   $(".p3-yes").click(function(){
	   _p3Yes='yes';
	   $(".p3-no .jqradio").removeClass("jqchecked");
       $(".p3-yes .jqradio").addClass("jqchecked");
	});
   $(".p3-no").click(function(){
	   _p3Yes='no';
	   $(".p3-yes .jqradio").removeClass("jqchecked");
       $(".p3-no .jqradio").addClass("jqchecked");
	});
   $(".p3-next").click(function(){
	   if('' == _p3Yes){
		   _popMsg('您是否同意《凤凰城小区业主公约》');return;
	   }
	   $.post("./api/?c=pz", {pyes:_p3Yes,p:'p3'}, function(data){
	    	 $(".p3").hide();
	    	 $(".p4").fadeIn();    
	   }, "json");
	});
   var _p4Yes='';
   $(".p4-yes").click(function(){
	   _p4Yes='yes';
	   $(".p4-no .jqradio").removeClass("jqchecked");
       $(".p4-yes .jqradio").addClass("jqchecked");
	});
   $(".p4-no").click(function(){
	   _p4Yes='no';
	   $(".p4-yes .jqradio").removeClass("jqchecked");
       $(".p4-no .jqradio").addClass("jqchecked");
	});
   $(".p4-next").click(function(){
	   if('' == _p4Yes){
		   _popMsg('您是否同意《凤凰城小区第一届业主委员会选举办法（草）》 ');return;
	   }
	   $.post("./api/?c=pz", {pyes:_p4Yes,p:'p4'}, function(data){
		     $(".p4").hide();
	    	 $(".p5").fadeIn();  
	   }, "json");
	});

	<?php
	 
	if ('yes' == $p2Yes){
	?>
	 _p2Yes='yes';
	$(".p2-yes .jqradio").addClass("jqchecked");
	<?php } ?>
	<?php if ('no' == $p2Yes){ ?>
	 _p2Yes='no';
	$(".p2-no .jqradio").addClass("jqchecked");
	<?php } ?>
 
	<?php if('yes' == $p3Yes){ ?>
	 _p3Yes='yes';
	 $(".p3-yes .jqradio").addClass("jqchecked");
	<?php } ?>
	<?php if('no' == $p3Yes){ ?>
	 _p3Yes='no';
	 $(".p3-no .jqradio").addClass("jqchecked");
	<?php } ?>

	<?php if('yes' == $p4Yes){ ?>
	 _p4Yes='yes';
	 $(".p4-yes .jqradio").addClass("jqchecked");
	<?php } ?>
	<?php if('no' == $p4Yes){ ?>
	 _p4Yes='no';
	 $(".p4-no .jqradio").addClass("jqchecked");
	<?php } ?>


	Array.prototype.remove = function(val) { 
	    var index = this.indexOf(val); 
	        if (index > -1) { 
	            this.splice(index, 1); 
	        } 
	};
	
    var _userCheck=[];
 
	$(".ui-checkbox").click(function(){
		 _popMsg('投票暂停中!');return;
		 
		 <?php if ('has' == $voteMsg){  ?>
		 _popMsg('您已投过票');return;
		 return;
		 <?php } ?>
		var _id=$(this).attr("date-id");
		 var _piao=parseInt($(".vote"+_id+" .piao").html());
		if(_userCheck.indexOf(_id) < 0){
			if(_userCheck.length > 10){console.log(_userCheck.length);return;}
		    _userCheck.push(_id);
	        $(".vote"+_id+" .jqcheck").addClass("jqchecked");
	        $(".vote"+_id+" .piao").html((_piao+1));
		}else{
			$(".vote"+_id+" .jqcheck").removeClass("jqchecked");
			_userCheck.remove(_id);
			$(".vote"+_id+" .piao").html((_piao-1));
	    }
		  
		console.log(_userCheck);
	});

	
	
	$("#jianyi").blur(function(){
		   if('' != $("#jianyi").val()){
	            $(".error-jianyi").html("");
		   }
	   });

	
    var _p51='';
	$(".p5-1-1").click(function(){
	   _p51=1;
	   _remove51();
       $(".p5-1-1 .jqradio").addClass("jqchecked");
	});
	$(".p5-1-2").click(function(){
		_p51=2;
		_remove51();
       $(".p5-1-2 .jqradio").addClass("jqchecked");
	});
	$(".p5-1-3").click(function(){
		_p51=3;
		_remove51();
       $(".p5-1-3 .jqradio").addClass("jqchecked");
	});
	function _remove51(){
		$(".p5-1-1 .jqradio").removeClass("jqchecked");
		$(".p5-1-2 .jqradio").removeClass("jqchecked");
		$(".p5-1-3 .jqradio").removeClass("jqchecked");
	}

	var _p52='';
	$(".p5-2-1").click(function(){
	   _p52=1;
	   _remove52();
       $(".p5-2-1 .jqradio").addClass("jqchecked");
	});
	$(".p5-2-2").click(function(){
		_p52=2;
		_remove52();
       $(".p5-2-2 .jqradio").addClass("jqchecked");
	});
	$(".p5-2-3").click(function(){
		_p52=3;
		_remove52();
       $(".p5-2-3 .jqradio").addClass("jqchecked");
	});
	function _remove52(){
		$(".p5-2-1 .jqradio").removeClass("jqchecked");
		$(".p5-2-2 .jqradio").removeClass("jqchecked");
		$(".p5-2-3 .jqradio").removeClass("jqchecked");
	}

	var _p53='';
	$(".p5-3-1").click(function(){
	   _p53=1;
	   _remove53();
       $(".p5-3-1 .jqradio").addClass("jqchecked");
	});
	$(".p5-3-2").click(function(){
		_p53=2;
		_remove53();
       $(".p5-3-2 .jqradio").addClass("jqchecked");
	});
	$(".p5-3-3").click(function(){
		_p53=3;
		_remove53();
       $(".p5-3-3 .jqradio").addClass("jqchecked");
	});
	function _remove53(){
		$(".p5-3-1 .jqradio").removeClass("jqchecked");
		$(".p5-3-2 .jqradio").removeClass("jqchecked");
		$(".p5-3-3 .jqradio").removeClass("jqchecked");
	}


	var _p54='';
	$(".p5-4-1").click(function(){
		_p54=1;
	   _remove54();
       $(".p5-4-1 .jqradio").addClass("jqchecked");
	});
	$(".p5-4-2").click(function(){
		_p54=2;
		_remove54();
       $(".p5-4-2 .jqradio").addClass("jqchecked");
	});
	function _remove54(){
		$(".p5-4-1 .jqradio").removeClass("jqchecked");
		$(".p5-4-2 .jqradio").removeClass("jqchecked");
	}

	var _p55='';
	$(".p5-5-1").click(function(){
		_p55=1;
	   _remove55();
       $(".p5-5-1 .jqradio").addClass("jqchecked");
	});
	$(".p5-5-2").click(function(){
		_p55=2;
		_remove55();
       $(".p5-5-2 .jqradio").addClass("jqchecked");
	});
	function _remove55(){
		$(".p5-5-1 .jqradio").removeClass("jqchecked");
		$(".p5-5-2 .jqradio").removeClass("jqchecked");
	}

	<?php if('' != $w1){ ?>
	  _p51='<?php echo $w1 ?>';
	  $(".p5-1-<?php echo $w1 ?> .jqradio").addClass("jqchecked");
	<?php } ?>
	
	<?php if('' != $w2){ ?>
	  _p52='<?php echo $w2 ?>';
	  $(".p5-2-<?php echo $w2 ?> .jqradio").addClass("jqchecked");
	<?php } ?>
	
	<?php if('' != $w3){ ?>
	  _p53='<?php echo $w3 ?>';
	  $(".p5-3-<?php echo $w3 ?> .jqradio").addClass("jqchecked");
	<?php } ?>
	
	<?php if('' != $w4){ ?>
	  _p54='<?php echo $w4 ?>';
	  $(".p5-4-<?php echo $w4 ?> .jqradio").addClass("jqchecked");
	<?php } ?>
	
	<?php if('' != $w5){ ?>
	  _p55='<?php echo $w5 ?>';
	  $(".p5-5-<?php echo $w5 ?> .jqradio").addClass("jqchecked");
	<?php } ?>

	 

	var _canVote=true;
	$(".p5-next").click(function(){
		 $.post("./api/?c=p5new", {p51:_p51,p52:_p52,p53:_p53,p54:_p54,p55:_p55
		   }, function(data){
			   window.location.href="p6.php";
			   }, "json");
		 return;
		  
		var _jianyi=$("#jianyi").val();
		<?php if ('has' == $voteMsg){  ?>
		   window.location.href="p6.php";
		 return;
		 <?php } ?>
		if(false == _canVote){return;}
		_canVote=false;
  
		$(".error-jianyi").html('');
		 window.setTimeout(function(){
			   _canVote=true;
		   }, 800);
		   if(_userCheck.length < 1){
			   _popMsg('请给候选人投票');return;
		   }
		    
		   var json = JSON.stringify(_userCheck);
		   $.post("./api/?c=vote", {u:json, jianyi:_jianyi}, function(data){
			   window.location.href="p6.php";
		   }, "json");
		   $.post("./api/?c=p5new", {p51:_p51,p52:_p52,p53:_p53,p54:_p54,p55:_p55
		   }, function(data){}, "json");
		    
		});
 
    <?php if (2 == $isok){ ?>
    _popMsg('您的资料未通过管理员审核');
    <?php } ?>

     
    
});
</script>
</body>
</html>